package com.tuo51.evaluate.service.impl;


import com.tuo51.evaluate.domain.news.ArticleCategory;
import com.tuo51.evaluate.repositories.article.ArticleCategoryRepository;
import com.tuo51.evaluate.service.article.ArticleCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.List;

/**
 * *******************************
 * Created by Ron.
 * form com.tuo51
 * on 2017/7/26
 * *******************************
 */
@Service
@Transactional
public class ArticleCategoryServiceImpl implements ArticleCategoryService {

    @Autowired
    ArticleCategoryRepository categoryRepository;

    @Override
    public List<ArticleCategory> getAllCategories(String channel) {

        // TODO：优化这个查询
        List<ArticleCategory> all = categoryRepository.findAllByChannelAndDeletedIsFalseAndParentIsNullAndHiddenIsFalseOrderByOrderWeightDesc(channel);

//        Map<String, ArticleCategory> cache = all.stream().collect(Collectors.toMap(ArticleCategory::getId, article->article));
//
//        all = all.stream().filter(k->{
//            if(k.getParent() == null){
//                return true;
//            }else{
//                cache.get(k.getParent());
//                return false;
//            }
//        }).collect(Collectors.toList());

        return all;
    }
}
